/**
 * Author@ Cheng Feitian
 * Date: 2021-3-25
 * Description: 深拷贝与浅拷贝
 */

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
const int maxn = 1024;

class Person
{
private:
public:
    Person();
    Person(int age, int height);
    Person(const Person & p);
    ~Person();
    int m_Age;
    int *m_Height;
};
Person::Person()
{
    cout << "Person类的默认构造函数调用" << endl;
}
Person::Person(int age, int height)
{
    m_Age = age;
    m_Height = new int(height);
    cout << "Person类的有参构造函数调用" << endl;
}
Person::Person(const Person & p){
    cout << "Person类的拷贝构造函数调用" << endl;
    m_Age = p.m_Age;
    m_Height = new int(*p.m_Height);
}
Person::~Person()
{
    //析构代码，将堆区开辟数据做释放操作
    if (m_Height != NULL)
    {
        delete m_Height;
        m_Height = NULL;
    }
    // delete m_Height;
    // m_Height = NULL;

    cout << "Person类的析构函数调用" << endl;
}

void test01()
{
    Person p1(18, 180);
    cout << "P1---" << "年龄：" << p1.m_Age << endl
         << "     " << "身高：" << *p1.m_Height << endl;
    
    Person p2(p1);
    cout << "P2---" << "年龄：" << p2.m_Age << endl
         << "     " << "身高：" << *p2.m_Height << endl;
}

int main()
{
    test01();
    return 0;
}
